package com.dhcc.sdc.busi.service.impl;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.dhcc.cdc.busi.dao.*;
import com.dhcc.cdc.busi.entity.*;
import com.dhcc.cdc.busi.service.ICdcDictionaryService;
import com.dhcc.cdc.sys.cache.config.CdcConfigCache;
import com.dhcc.cdc.sys.dao.DictionaryMapper;
import com.dhcc.cdc.sys.entity.DictionaryEntity;
import com.dhcc.cdc.sys.service.IConfigurationService;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.api.dao.SdsToolSdkMapper;
import com.dhcc.sdc.base.dao.SdcBaseAssessmenentryMapper;
import com.dhcc.sdc.base.entity.SdcBaseAssessmenentryEntity;
import com.dhcc.sdc.busi.dao.SdcBusiEvaluationHisMapper;
import com.dhcc.sdc.busi.dao.SdcBusiEvaluationItemMapper;
import com.dhcc.sdc.busi.dao.SdcBusiEvaluationMapper;
import com.dhcc.sdc.busi.dao.SdcBusiQcMrlistMapper;
import com.dhcc.sdc.busi.entity.SdcBusiEvaluationEntity;
import com.dhcc.sdc.busi.entity.SdcBusiEvaluationHisEntity;
import com.dhcc.sdc.busi.entity.SdcBusiEvaluationItemEntity;
import com.dhcc.sdc.busi.entity.SdcBusiQcMrlistEntity;
import com.dhcc.sdc.busi.service.ISdcQcFormShowService;
import com.dhcc.sds.base.cache.formitem.FormItemCache;
import com.dhcc.sds.base.cache.formitemdic.FormItemDicCache;
import com.dhcc.sds.base.cache.formitemmatchrule.FormItemMatchRuleCache;
import com.dhcc.sds.base.dao.*;
import com.dhcc.sds.base.entity.*;
import com.dhcc.sds.busi.dao.SdsQcFormShowMapper;
import com.dhcc.sds.busi.dao.SdsQcfitemExecresultMapper;
import com.dhcc.sds.busi.dao.SdsQcincaseMapper;
import com.dhcc.sds.busi.dto.SdsQcFormItemDto;
import com.dhcc.sds.busi.entity.SdsQcfitemExecresultEntity;
import com.dhcc.sds.busi.entity.SdsQcincaseEntity;
import com.dhcc.sds.busi.service.ISdsQcFormShowService;
import com.dhcc.sds.busi.service.ISdsQcfitemExecresultService;
import com.dhcc.sds.standard.dao.SdsStandDicMatchMapper;
import com.dhcc.sds.standard.dao.SdsStandDicMatchParamMapper;
import com.dhcc.sds.standard.dao.SdsStandSourceMapper;
import com.dhcc.sds.standard.dto.CdcExaminateDto;
import com.dhcc.sds.standard.dto.CdcLisReportDto;
import com.dhcc.sds.standard.dto.CdcNurDto;
import com.dhcc.sds.standard.dto.CdcOrdmastDto;
import com.dhcc.sds.standard.entity.SdsStandDicMatchParamEntity;
import com.dhcc.sds.standard.entity.SdsStandRuleBaseEntity;
import com.dhcc.sds.standard.entity.SdsStandSourceEntity;
import com.dhcc.sds.standard.service.ISdsStandDicService;
import com.dhcc.sds.standard.service.ISdsStandRuleBaseService;
import com.dhcc.sds.standard.service.IsdsStandRuleCalService;
import com.dhcc.sds.util.DateUtil;
import com.dhcc.sds.util.IdentityCodeUtil;
import com.dhcc.sds.ws.dhcmessage.DHCMessageServiceLocator;
import com.dhcc.sds.ws.dhcmessage.DHCMessageServiceSoap;
import com.googlecode.aviator.AviatorEvaluator;
import org.apache.commons.jexl2.Expression;
import org.apache.commons.jexl2.JexlContext;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.MapContext;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.text.StrSubstitutor;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.xml.rpc.ServiceException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @version 1.0 DHCC
 * @Description: 描述
 * @Project Name:
 * @Package Name:
 * @File Name:
 * @author:yanghangwei
 * @date:
 * @Copyright: (c) DHCC All rights reserved.
 */
@Service("sdcQcFormShowService")
public class SdcQcFormShowServiceImpl implements ISdcQcFormShowService {
    @Autowired
    private SdsQcformItemMapper sdsQcformItemMapper;
    @Autowired
    private SdsQcfitemExecresultMapper sdsQcfitemExecresultMapper;
    @Autowired
    private SdcBusiQcMrlistMapper sdcBusiQcMrlistMapper;
    /**
     * 小括号及其里面内容
     */
    private static String p1 = "\\(.*?\\)";
    /**
     * 中括号及其里面内容
     */
    private static String p2 = "\\[.*?\\]";
    /**
     * 大括号及其里面内容
     */
    private static String p3 = "\\{.*?\\}";

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 查找项目的子项目及孙...孙孙项目（递归）
     */
    public Set<SdsQcformItemEntity> findSubItems(Long entityId, String itemCode, Set<SdsQcformItemEntity> linkItemList) {
        List<SdsQcformItemEntity> tmpList1 = FormItemCache.me().getFormItemByExp(entityId, "(" + itemCode + ")");

        for (SdsQcformItemEntity item : tmpList1) {
            if (linkItemList.contains(item)) {
                continue;
            }
            linkItemList.add(item);
            Set<SdsQcformItemEntity> tmpList2 = findSubItems(entityId, item.getBtCode(), linkItemList);
            if (tmpList2.size() > 0) {
                linkItemList.addAll(tmpList2);
            }
        }

        return linkItemList;
    }

    /**
     * 计算项目的显隐结果
     *
     * @param itemObj
     * @return
     */
    public Map<String, Object> calcExpReslut(JSONObject itemObj, Map<String, Object> editMap) {

        Long itemId = Long.valueOf(itemObj.getString("itemId"));
        String triExp = StringEscapeUtils.unescapeHtml(itemObj.getString("triExp"));
        JSONArray linkItemArr = itemObj.getJSONArray("linkItem");

        Map<String, Object> resMap = new HashMap<>();
        resMap.put("itemId", itemId);
        resMap.put("itemCode", itemObj.getString("itemCode"));
        resMap.put("showFlg", "0");

        if (linkItemArr.size() == 0) {
            resMap.put("showFlg", "0");
            return resMap;
        }

        Map tmpItemMap = new HashMap();
        for (int i = linkItemArr.size() - 1; i >= 0; i--) {
            JSONObject obj = linkItemArr.getJSONObject(i);
            String itemCode = obj.getString("itemCode");
            if (editMap.get(itemCode) != null && editMap.get(itemCode).equals("0")) {
                tmpItemMap.put(itemCode, "");
            } else {
                tmpItemMap.put(itemCode, obj.get("itemVal"));
            }
        }

        // 查找规则公式中括号以内的字符
        Pattern pat1 = Pattern.compile(p1);
        // 替换关联项目的值
        Matcher m1 = pat1.matcher(triExp);
        while (m1.find()) {
            if (m1.group().contains("\"")) {// 如果里面是常量，则继续下一个
                continue;
            }
            String subItemCode = m1.group().substring(1, m1.group().length() - 1);
            String subItemVal = String.valueOf(tmpItemMap.get(subItemCode));
//            if (triExp.contains("\"")) {
            subItemVal = "(\"" + subItemVal + "\")";
//            }
            triExp = triExp.replace(m1.group(), subItemVal);
        }

        if (!triExp.matches(p3)) {
            String[] expArr = triExp.split(":", 2);
            String subExpType_l = expArr[0];
            String subExp_l = expArr[1];

            long divisor = 1;
            if (subExpType_l.contains("CALC")) {
                switch (subExpType_l) {
                    case "CALC-h":
                        // 1小时毫秒数
                        divisor = 60 * 60 * 1000;
                        break;
                    case "CALC-m":
                        // 一分钟毫秒数
                        divisor = 60 * 1000;
                        break;
                    case "CALC-day":
                        // 一天毫秒数
                        divisor = 24 * 60 * 60 * 1000;
                        break;
                    case "CALC-month":
                        // 一个月毫秒数
                        divisor = 30l * 24l * 60l * 60l * 1000l;
                        break;
                    case "CALC-year":
                        // 一年毫秒数
                        divisor = 12l * 30l * 24l * 60l * 60l * 1000l;
                        break;
                    default:
                        break;
                }
                // 查找规则公式中小括号以内的值
                // 替换关联项目的值
                m1 = pat1.matcher(subExp_l);
                String execExp = subExp_l;
                while (m1.find()) {
                    if ("()".equals(m1.group()) || "(\"\")".equals(m1.group()) || "(\"null\")".equals(m1.group())) {
                        execExp = execExp.replace(m1.group(), "0");
                        continue;
                    }
                    String val = m1.group().substring(1, m1.group().length() - 1).replace("\"", "");
                    Long times = DateUtil.getTime(val);
                    int minutes = Math.toIntExact(times / divisor);
                    execExp = execExp.replace(val, String.valueOf(minutes));
                }
                triExp = triExp.replace(subExp_l, execExp);
            }
            triExp = triExp.replace(subExpType_l, "");
        } else {

            // 查找规则公式中大括号以内的字符
            Pattern pat3 = Pattern.compile(p3);
            // 替换关联项目的值
            Matcher m3 = pat3.matcher(triExp);
            while (m3.find()) {
                // 大括号中间的表达式
                String subExpStr_l = m3.group().substring(1, m3.group().length() - 1);
                String[] expArr = subExpStr_l.split(":", 2);
                String subExpType_l = expArr[0];
                String subExp_l = expArr[1];

                long divisor = 1;
                if (subExpType_l.contains("CALC")) {
                    switch (subExpType_l) {
                        case "CALC-h":
                            // 1小时毫秒数
                            divisor = 60 * 60 * 1000;
                            break;
                        case "CALC-m":
                            // 一分钟毫秒数
                            divisor = 60 * 1000;
                            break;
                        case "CALC-day":
                            // 一天毫秒数
                            divisor = 24 * 60 * 60 * 1000;
                            break;
                        case "CALC-month":
                            // 一个月毫秒数
                            divisor = 30l * 24l * 60l * 60l * 1000l;
                            break;
                        case "CALC-year":
                            // 一年毫秒数
                            divisor = 12l * 30l * 24l * 60l * 60l * 1000l;
                            break;
                        default:
                            break;
                    }
                    // 查找规则公式中小括号以内的值
                    // 替换关联项目的值
                    m1 = pat1.matcher(subExp_l);
                    String execExp = subExp_l;
                    while (m1.find()) {
                        if ("()".equals(m1.group()) || "(\"\")".equals(m1.group()) || "(\"null\")".equals(m1.group())) {
                            execExp = execExp.replace(m1.group(), "0");
                            continue;
                        }
                        String val = m1.group().substring(1, m1.group().length() - 1).replace("\"", "");
                        Long times = DateUtil.getTime(val);
                        int minutes = Math.toIntExact(times / divisor);
                        execExp = execExp.replace(val, String.valueOf(minutes));
                    }
                    triExp = triExp.replace(subExp_l, execExp);
                }
                triExp = triExp.replace(subExpStr_l, subExp_l);
                triExp = triExp.replace(subExpType_l, "");
            }
        }
        triExp = triExp.replace(":", "");
        if (triExp.contains("contains")) {
            triExp = modifyExpression(triExp);
        }
        // 将表达式中的大括号中括号替换为小括号，以及其他其他字符替换为可执行字符
        triExp = triExp.replace("{", "(").replace("}", ")");
        triExp = triExp.replace("[", "(").replace("]", ")");
        triExp = triExp.replace("contains(\"\")", "contains(\",,\")");
        triExp = triExp.replace("oth", "OTH").replace("def", "DEF");

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        // 运算前置条件表达式
        try {
            if ((boolean) engine.eval(triExp)) {
                resMap.put("showFlg", "1");
                return resMap;
            }
        } catch (ScriptException e) {
            resMap.put("showFlg", "1");
            return resMap;
        }

        return resMap;
    }

    public String modifyExpression(String expression) {
        String aExp = expression;

        //判断表达式中有无中括号
        if (!expression.matches(p2)) {
            if (!expression.contains("contains")) {
                return aExp;
            }
            // 循环处理原始表达式中的子表达式
            String[] subStrArr = aExp.split(".contains");
            for (int ExpInd = 0; ExpInd < subStrArr.length; ExpInd++) {
                String expSub = subStrArr[ExpInd];  // 提取子表达式
                // 提取引号内的内容
                String regExp = "(\").*?(\")";
                Pattern pattern = Pattern.compile(regExp);
                Matcher matcher = pattern.matcher(expSub);
                while (matcher.find()) {
                    String group = matcher.group();
                    String result = group.substring(1, group.length() - 1);
                    result = "\"," + result + ",\"";
                    aExp = aExp.replaceFirst(group, result);
                }
            }
        } else {
            // 查找规则公式中中括号以内的字符
            Pattern pat2 = Pattern.compile(p2);
            // 替换关联项目的值
            Matcher m2 = pat2.matcher(aExp);
            while (m2.find()) {
                String subGroup = m2.group();
                if (!subGroup.contains("contains")) {
                    continue;
                }
                String tmpGroup = subGroup;
                String tmpSubFroup = subGroup.substring(1, subGroup.length() - 1);
                // 循环处理原始表达式中的子表达式
                String[] subStrArr = tmpSubFroup.split(".contains");
                for (int ExpInd = 0; ExpInd < subStrArr.length; ExpInd++) {
                    String expSub = subStrArr[ExpInd];  // 提取子表达式
                    // 提取引号内的内容
                    String regExp = "(\").*?(\")";
                    Pattern pattern = Pattern.compile(regExp);
                    Matcher matcher = pattern.matcher(expSub);
                    while (matcher.find()) {
                        String group = matcher.group();
                        String result = group.substring(1, group.length() - 1);
                        result = "\"," + result + ",\"";
                        tmpGroup = tmpGroup.replaceFirst(group, result);
                    }
                }
                aExp = aExp.replace(subGroup, tmpGroup);
            }
        }

        return aExp;
    }

    /**
     * 计算本项目的显隐属性
     *
     * @param mrListId
     * @param formItem
     * @return
     * @throws ScriptException
     */
    @Override
    public Integer calcTriggerExp(Long mrListId, SdsQcformItemEntity formItem, Map<String, Object> editMap) {
        // 项目全部默认显示
        Integer editPower = 1;
        //1、ScriptEngineManager是JDK6提出的相关方法，这方式的主要目的就是用来对脚本语言的处理。
        //2、ScriptEngineManager是在java的javax.script的包下，是Java原生提供的脚本语言处理方法。
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        if (CommonUtil.isEmpty(formItem.getTriggerExp())) {
            return editPower;
        } else {
            // 带表达式的项目默认不显示，只有表达式条件成立之后才显示
            editPower = 0;
            String triggerExp = formItem.getTriggerExp();
            Long entityId = formItem.getEntityId();
            // 查找规则公式中括号以内的字符
            Pattern p = Pattern.compile(p1);// 查找规则公式中括号以内的字符
            // 替换关联项目的值
            Matcher m = p.matcher(triggerExp);
            while (m.find()) {// 遍历找到的所有括号
                if (m.group().contains("\"")) { // 如果里面是常量，则继续下一个
                    continue;
                }
                // 取得关联项目代码
                String itemCode = m.group().substring(1, m.group().length() - 1);
                // 通过项目代码查询项目id并取值
//                SdsQcformItemEntity linkItem = new SdsQcformItemEntity();
//                linkItem.setEntityId(entityId);
//                linkItem.setBtCode(itemCode);
//                linkItem = sdsQcformItemMapper.selectOne(linkItem);
                String linkVal = "";
                if (editMap.get(itemCode) != null && (Integer) editMap.get(itemCode) == 0) {
                    linkVal = "";
                } else {
                    SdsQcformItemEntity linkItem = FormItemCache.me().getFormItemByCode(entityId, itemCode);

                    SdsQcfitemExecresultEntity linkItemExec = new SdsQcfitemExecresultEntity();
                    linkItemExec.setformItemId(linkItem.getId());
                    linkItemExec.setInCaseId(mrListId);
                    linkItemExec = sdsQcfitemExecresultMapper.selectOne(linkItemExec);
                    // 如果有项目值为空，则默认不符合
                    if (!CommonUtil.isEmpty(linkItemExec)) {
                        linkVal = linkItemExec.getItemResult();
                    }
                }
                // 如果表达式有引号，那么是字符串比较，给项目值加上双引号
//                if (triggerExp.contains("\"")) {
                linkVal = "(\"" + linkVal + "\")";
//                }
                // 将值替换表达式中项目代码
                triggerExp = triggerExp.replace(m.group(), linkVal);
            }
            if (!triggerExp.matches(p3)) {
                String[] expArr = triggerExp.split(":", 2);
                String subExpType_l = expArr[0];
                String subExp_l = expArr[1];

                long divisor = 1;
                if (subExpType_l.contains("CALC")) {
                    switch (subExpType_l) {
                        case "CALC-h":
                            // 1小时毫秒数
                            divisor = 60 * 60 * 1000;
                            break;
                        case "CALC-m":
                            // 一分钟毫秒数
                            divisor = 60 * 1000;
                            break;
                        case "CALC-day":
                            // 一天毫秒数
                            divisor = 24 * 60 * 60 * 1000;
                            break;
                        case "CALC-month":
                            // 一个月毫秒数
                            divisor = 30l * 24l * 60l * 60l * 1000l;
                            break;
                        case "CALC-year":
                            // 一年毫秒数
                            divisor = 12l * 30l * 24l * 60l * 60l * 1000l;
                            break;
                        default:
                            break;
                    }
                    // 查找规则公式中小括号以内的值
                    // 替换关联项目的值
                    m = p.matcher(subExp_l);
                    String execExp = subExp_l;
                    while (m.find()) {
                        if ("()".equals(m.group()) || "(\"\")".equals(m.group())) {
                            execExp = execExp.replace(m.group(), "0");
                            continue;
                        }
                        String val = m.group().substring(1, m.group().length() - 1).replace("\"", "");
                        Long times = DateUtil.getTime(val);
                        int minutes = Math.toIntExact(times / divisor);
                        execExp = execExp.replace(val, String.valueOf(minutes));
                    }
                    triggerExp = triggerExp.replace(subExp_l, execExp);
                }
                triggerExp = triggerExp.replace(subExpType_l, "");
            } else {
                // 查找规则公式中大括号以内的字符
                Pattern pat3 = Pattern.compile(p3);
                // 替换关联项目的值
                Matcher m3 = pat3.matcher(triggerExp);
                while (m3.find()) {
                    // 大括号中间的表达式
                    String subExpStr_l = m3.group().substring(1, m3.group().length() - 1);
                    String[] expArr = subExpStr_l.split(":", 2);
                    String subExpType_l = expArr[0];
                    String subExp_l = expArr[1];

                    long divisor = 1;
                    if (subExpType_l.contains("CALC")) {
                        switch (subExpType_l) {
                            case "CALC-h":
                                // 1小时毫秒数
                                divisor = 60 * 60 * 1000;
                                break;
                            case "CALC-m":
                                // 一分钟毫秒数
                                divisor = 60 * 1000;
                                break;
                            case "CALC-day":
                                // 一天毫秒数
                                divisor = 24 * 60 * 60 * 1000;
                                break;
                            case "CALC-month":
                                // 一个月毫秒数
                                divisor = 30l * 24l * 60l * 60l * 1000l;
                                break;
                            case "CALC-year":
                                // 一年毫秒数
                                divisor = 12l * 30l * 24l * 60l * 60l * 1000l;
                                break;
                            default:
                                break;
                        }
                        // 查找规则公式中小括号以内的值
                        // 替换关联项目的值
                        m = p.matcher(subExp_l);
                        String execExp = subExp_l;
                        while (m.find()) {
                            if ("()".equals(m.group()) || "(\"\")".equals(m.group())) {
                                execExp = execExp.replace(m.group(), "0");
                                continue;
                            }
                            String val = m.group().substring(1, m.group().length() - 1).replace("\"", "");
                            Long times = DateUtil.getTime(val);
                            int minutes = Math.toIntExact(times / divisor);
                            execExp = execExp.replace(val, String.valueOf(minutes));
                        }
                        triggerExp = triggerExp.replace(subExp_l, execExp);
                    }
                    triggerExp = triggerExp.replace(subExpStr_l, subExp_l);
                    triggerExp = triggerExp.replace(subExpType_l, "");
                }
            }
            triggerExp = triggerExp.replace(":", "");
            if (triggerExp.contains("contains")) {
                triggerExp = modifyExpression(triggerExp);
            }
            // 将表达式中的大括号中括号替换为小括号，以及其他其他字符替换为可执行字符
            triggerExp = triggerExp.replace("{", "(").replace("}", ")");
            triggerExp = triggerExp.replace("[", "(").replace("]", ")");
            triggerExp = triggerExp.replace("contains(\"\")", "contains(\",,\")");
            triggerExp = triggerExp.replace("oth", "OTH").replace("def", "DEF");

            // 运算前置条件表达式
            try {
                if ((boolean) engine.eval(triggerExp)) {
                    editPower = 1;
                }
            } catch (ScriptException e) {
                // 表达式解析失败，默认返回1
                return 1;
            }
        }
        return editPower;
    }

    /**
     * @param mrListId
     * @return
     * @throws Exception
     * @author yanghangwei
     */
    @Override
    public List<SdsQcFormItemDto> getBusiItemResult(Long mrListId) throws Exception {
        List<SdsQcFormItemDto> formItemList = new ArrayList<>();
        if (CommonUtil.isEmpty(mrListId)) {
            return formItemList;
        }
        // 获取入组信息
        SdcBusiQcMrlistEntity mrEntity = this.sdcBusiQcMrlistMapper.selectById(mrListId);
        if (CommonUtil.isEmpty(mrEntity)) {
            return formItemList;
        }
        Map params = new HashMap();
        params.put("entityId", mrEntity.getEntityId());
        params.put("mrListId", mrListId);
        List<Map<String, Object>> itemList = sdsQcformItemMapper.getBusiItemResult(params);
        int l = itemList.size();
        SdsQcformItemEntity formItem;
        SdsQcFormItemDto itemDto;
        Map<String, Object> editPowerMap = new HashMap<>();
        for (int i = 0; i < l; i++) {
            itemDto = new SdsQcFormItemDto();
            Integer editPower = 1;
            Map<String, Object> map = itemList.get(i);
            if (CommonUtil.isNotEmpty(map.get("triggerExp"))) {
                formItem = new SdsQcformItemEntity();
                formItem.setId(Long.valueOf(map.get("itemId").toString()));
                formItem.setEntityId(Long.valueOf(map.get("entityId").toString()));
                formItem.setTriggerExp(map.get("triggerExp").toString());
                // 根据前置条件，计算项目显隐属性
                editPower = this.calcTriggerExp(mrListId, formItem, editPowerMap);
            }
            itemDto.setId(Long.valueOf(map.get("itemId").toString()));
            if (CommonUtil.isNotEmpty(map.get("itemResult"))) {
                itemDto.setExecResult(map.get("itemResult").toString());
            }
            editPowerMap.put(map.get("btCode").toString(), editPower);
            itemDto.setEditPower(editPower);
            itemDto.setBtItemCat(map.get("itemCat").toString());
            itemDto.setBtItemSubCat(map.get("itemSubCat").toString());
            formItemList.add(itemDto);
        }
        return formItemList;
    }

    public static boolean isJson(String content) {
        if (CommonUtil.isEmpty(content)) {
            return false;
        }
        try {
            JSONObject.parseObject(content);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

}